package sunwul.hospital.hosp.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sunwul.hospital.hosp.service.HospitalService;
import sunwul.hospital.common.helper.HttpRequestHelper;
import sunwul.hospital.common.result.Result;
import sunwul.hospital.model.model.hosp.Hospital;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author sunwul
 * @date 2023/11/2 17:26:40
 * @description  对接service-manage模块
 */
@Api(tags = "医院信息管理")
@RestController
@RequestMapping("/api/hosp")
public class HospitalApiController {

    @Autowired
    HospitalService hospitalService;

    @ApiOperation(value = "上传医院详细信息")
    @PostMapping("saveHospital")
    public Result saveHospital(HttpServletRequest request) {
        // 获取参数
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);

        hospitalService.save(paramMap);
        return Result.ok();
    }

    @ApiOperation(value = "查询医院详细信息")
    @PostMapping("hospital/show")
    public Result getHospital(HttpServletRequest request) {
        // 获取参数
        Map<String, String[]> requestMap = request.getParameterMap();
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);

        Hospital hospital = hospitalService.getHospitalByCode(paramMap);
        return Result.ok(hospital);
    }
}
